/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lcfgly.Form.Validation;

import com.lcfgly.Database.ShopArchives;
import com.lcfgly.util.CharFilter;
import java.util.Date;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author lcfgly
 */
public class ArchivesValidation implements Validator{

    @Override
    public boolean supports(Class<?> clazz) {
        return ShopArchives.class.equals(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmpty(errors, "title",null, "标题不能为空");
        ShopArchives arc=(ShopArchives)target;
        if(arc.getUpdatetime() == null)
            arc.setUpdatetime(new Date(new Date().getTime()));
        arc.setBody(CharFilter.getNoScriptString(arc.getBody()));
    }
    
}
